package com.qf.controller;

import com.qf.constans.ResultCode;
import com.qf.dto.R;
import com.qf.dto.UsersDto;
import com.qf.exceptions.AddDataException;
import com.qf.pojo.Users;
import com.qf.service.IUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/users")
public class UsersController {

    private IUsersService usersService;
    @Autowired
    public void setUsersService(IUsersService usersService) {
        this.usersService = usersService;
    }

    @PostMapping("/user")
    public R addUsers(@RequestBody UsersDto users){
        System.out.println("添加用户了");

        if(users==null||users.isNull()){
            throw new AddDataException("数据不完整", ResultCode.NULL_DATA);
        }
        System.out.println("添加用户");
        int i = usersService.addUser(users);

        return R.setOk(null);
    }

}
